<?php
/*
 * Created on Sep 15, 2010
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 class HttpUtils 
 {
	public function fetch_url($url, $code_on_fail = false, $interface = null) 
	{
	  $ch = curl_init($url);
	
	  curl_setopt($ch, CURLOPT_HEADER, 0);
	  curl_setopt($ch, CURLOPT_FAILONERROR, 1);
	  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	  if ($interface !== null) {
	    curl_setopt($ch, CURLOPT_INTERFACE, $interface);
	  }// end if
	
	  $content = curl_exec($ch);
	  $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	  curl_close($ch);
	
	  if ($content === false && $code_on_fail === true) {
	    return $http_code;
	  }// end if
	  return $content;
	}// end fun
 }
 
?>
